#include "input-field.h"
#include <string.h>
#include <stdlib.h>
#include "widget-container.h"

input_field_t* input_field_new(const gchar* say, const gchar* default_value){
	input_field_t* result = malloc(sizeof(input_field_t));
	result->label = gtk_label_new_with_mnemonic(say);
	gtk_widget_show(result->label);

	result->value = gtk_entry_new();
	gtk_entry_set_activates_default(GTK_ENTRY(result->value), TRUE);
	gtk_entry_set_text(GTK_ENTRY(result->value), default_value);
	gtk_widget_show(result->value);
	gtk_label_set_mnemonic_widget(GTK_LABEL(result->label), result->value);

	result->controls = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
	gtk_box_pack_start(GTK_BOX(result->controls), result->label, FALSE, FALSE, 0);
	gtk_box_pack_end(GTK_BOX(result->controls), result->value, FALSE, FALSE, 0);

	return result;
}

const gchar* input_field_get_value(input_field_t* input_field){
	return gtk_entry_get_text(GTK_ENTRY(input_field->value));
}

void input_field_set_value(input_field_t* input_field, const gchar* value){
	gtk_entry_set_text(GTK_ENTRY(input_field->value), value);
}

	//set visibility for password field
input_field_t* input_field_set_password_field(input_field_t* input_field, gboolean is_password_field){
	gtk_entry_set_visibility(GTK_ENTRY(input_field->value), !is_password_field);
	return input_field;
}

void input_field_destroy(input_field_t* input_field){
	widget_container_destroy(input_field);
	free(input_field);
}
input_field_t* input_field_new_password(const gchar* say, const gchar* default_value){
	return input_field_set_password_field(input_field_new(say, default_value), TRUE);
}
input_field_t* input_field_new_with_tooltip(const gchar* say, const gchar* default_value, const gchar* tooltip){
	input_field_t* input_field = input_field_new(say, default_value);
	gtk_widget_set_tooltip_text(input_field->value, tooltip);
	return input_field;
}
